package cn.jx.asc.common.untils;

import sun.misc.BASE64Encoder;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @author 周国伟
 * @desc TODO
 * @date 2018/6/1 14:38
 * @describe 密码加密
 */
public class SecurityUtils {

    public static  String encryptPassword(String password) throws NoSuchAlgorithmException, UnsupportedEncodingException {
         MessageDigest md5 = MessageDigest.getInstance("MD5");
        BASE64Encoder base64Encoder = new BASE64Encoder();
        String result = base64Encoder.encode(md5.digest(password.getBytes("UTF-8")));
        return  result;
    }

    public static boolean checkPassword(String inputpwd,String dbpwd) throws UnsupportedEncodingException, NoSuchAlgorithmException {
        String result = encryptPassword(inputpwd);
        if(result.equals(dbpwd)){
            return true;
        }else {
            return false;
        }

    }
}
